import { View } from "../../../../mvc/core/View";
import { ShortcutsItem } from "../../shortcuts/ShortcutsItem";
import { CDItemData } from "../../../cache/CDItem/CDItemData";
import { LayerManager } from "../../../manager/LayerManager";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ObjCreate } from "../../common/ObjCreate";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { TweenMax } from "../../../../../com/greensock/TweenMax";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { SceneRange } from "../../../scene/map/SceneRange";
import { Global } from "../../../../../com/gengine/global/Global";
import { ItemData } from "../../../resource/info/ItemData";
import { RolePlayer } from "../../../scene/player/entity/RolePlayer";
import { TweenLite } from "../../../../../com/greensock/TweenLite";
import { MsgManager } from "../../../manager/MsgManager";
import { GameProxy } from "../../../mvc/GameProxy";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class DefendSkillPropListPanel
    
    export  class DefendSkillPropListPanel extends View
    {
        constructor(arg1: int=5, arg2: Boolean=false, arg3: string="", arg4: string="", arg5: Boolean=false)
        {
            super();
            this._propVec = new Vector.<ShortcutsItem>();
            this._moveRec = new Object /* flash.geom.Rectangle */();
            this._propList = [];
            this._cd = new CDItemData();
            this._needHideBtn = arg2;
            this._needShowNum = arg5;
            this._showingTips = arg3;
            this._hidingTips = arg4;
            this._skillMaxNum = arg1;
            this.layer = LayerManager.uiLayer;
            this._container = new Object /* flash.display.Sprite */();
            this.addChild(this._container);
            this.createChildren();
            this.initShowHideBtn();
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.removeFromStageHandler);
            return;
        }

        protected createChildren(): void
        {
            var loc1=null;
            LoaderManager.instance.load("DefendCopyPropBg.png", this.onPropListBgLoaded);
            var loc2=0;
            while (loc2 < this._skillMaxNum) 
            {
                loc1 = new ShortcutsItem(loc2);
                loc1.x = 18 + loc2 * this._skillSlotWidth;
                loc1.y = 0;
                loc1.isDragAble = false;
                loc1.isDropAble = false;
                loc1.isThrowAble = false;
                loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClick);
                this._container.addChild(loc1);
                this._propVec.push(loc1);
                ++loc2;
            }
            this._moveBtn = ObjCreate.createGButton("", 223, 18, 24, 22, this._container, "MoveBtn2");
            this._moveBtn.x = 223 + (this._skillMaxNum - this._skillDefaultNum) * this._skillSlotWidth;
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(60053), "#FFFFFF");
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            return;
        }

        protected initShowHideBtn(): void
        {
            if (!this._needHideBtn) 
            {
                return;
            }
            this._btnHide = GlobalClass.getInstance("showBtn");
            this._btnHide.width = 24;
            this._btnHide.height = 22;
            this._btnHide.x = 236 + (this._skillMaxNum - this._skillDefaultNum) * this._skillSlotWidth;
            this._btnHide.y = 10;
            this.addChild(this._btnHide);
            this._btnHide.addEventListener(flash.events.MouseEvent.CLICK, this.clickHideHandler);
            this.hideShowOpComplete();
            return;
        }

        protected clickHideHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._needHideBtn) 
            {
                return;
            }
            if (this._tweening) 
            {
                return;
            }
            if (this._btnHide.scaleX != 1) 
            {
                this._btnHide.scaleX = 1;
                this.showBody();
            }
            else 
            {
                this._btnHide.scaleX = -1;
                this.hideBody();
            }
            return;
        }

        protected hideBody(): void
        {
            if (!this._needHideBtn) 
            {
                return;
            }
            this._tweening = true;
            var loc1=this._btnHide.x;
            var loc2=this._btnHide.y;
            TweenMax.to(this._container, this._hideTweeingTime, {"x": loc1, "y": loc2, "scaleX": 0, "scaleY": 0, "onComplete": this.hideShowOpComplete});
            return;
        }

        protected showBody(): void
        {
            if (!this._needHideBtn) 
            {
                return;
            }
            this._tweening = true;
            TweenMax.to(this._container, this._hideTweeingTime, {"x": 0, "y": 0, "scaleX": 1, "scaleY": 1, "onComplete": this.hideShowOpComplete});
            return;
        }

        protected hideShowOpComplete(): void
        {
            if (!this._needHideBtn) 
            {
                return;
            }
            this._tweening = false;
            ToolTipsManager.unregister(this._btnHide);
            var loc1=this._showingTips;
            if (this._btnHide.scaleX == -1) 
            {
                loc1 = this._hidingTips;
            }
            ToolTipsManager.register(this._btnHide, null, loc1);
            return;
        }

        public /* override */ get width(): number
        {
            return this._skillBgNoSkillWidth + this._skillMaxNum * this._skillSlotWidth;
        }

        protected onPropListBgLoaded(arg1: ImageInfo): void
        {
            var loc1=new ScaleBitmap(arg1.bitmapData.clone());
            loc1.scale9Grid = new Object /* flash.geom.Rectangle */(25, 0, 190, 54);
            loc1.width = this._skillBgNoSkillWidth + this._skillMaxNum * this._skillSlotWidth;
            loc1.height = 54;
            this._container.addChildAt(loc1, 0);
            return;
        }

        protected onMoveBtnMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._moveRec.x = 0;
            this._moveRec.y = 0;
            this._moveRec.width = SceneRange.display.width - 30;
            this._moveRec.height = SceneRange.display.height - 30;
            startDrag(false, this._moveRec);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        protected onStageMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            stopDrag();
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        public setPropListData(arg1: Array<any>): void
        {
            var loc1=0;
            var loc2=null;
            if (this._propList.length < arg1.length) 
            {
                loc1 = (arg1.length - 1);
                loc2 = new ItemData(arg1[loc1]);
                LoaderManager.instance.load(loc2.itemInfo.url, this.onImageLoaded, 3, loc1);
            }
            this._propList = arg1;
            loc1 = 0;
            while (loc1 < this._skillMaxNum) 
            {
                if (loc1 < arg1.length) 
                {
                    this._propVec[loc1].dragSource = new ItemData(arg1[loc1]);
                    if (!this._needShowNum) 
                    {
                        this._propVec[loc1].setAmountText(-1);
                    }
                    this._propVec[loc1].doCoolDown(this._cd);
                }
                else 
                {
                    this._propVec[loc1].dragSource = null;
                }
                ++loc1;
            }
            return;
        }

        protected onImageLoaded(arg1: ImageInfo): void
        {
            var loc4=null;
            var loc1=RolePlayer.instance.stagePointX;
            var loc2=RolePlayer.instance.stagePointY - 55;
            var loc3=arg1.extData as int;
            loc4 = this.localToGlobal(new Object /* flash.geom.Point */(this._propVec[loc3].x + 3, this._propVec[loc3].y + 3));
            var loc5;
            (loc5 = new Object /* flash.display.Bitmap */(arg1.bitmapData)).x = loc1;
            loc5.y = loc2;
            loc5.width = 32;
            loc5.height = 32;
            LayerManager.topLayer.addChild(loc5);
            TweenLite.to(loc5, 1.5, {"x": loc4.x, "y": loc4.y, "onComplete": this.onFlyComplete, "onCompleteParams":[loc5]});
            return;
        }

        protected onFlyComplete(arg1: Object /* flash.display.Bitmap */): void
        {
            if (arg1 && arg1.parent) 
            {
                arg1.parent.removeChild(arg1);
                arg1 = null;
            }
            return;
        }

        protected onItemClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as ShortcutsItem;
            if (loc1.playingEffect) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60054));
            }
            else if (loc1.dragSource) 
            {
                if (loc1.itemData) 
                {
                    GameProxy.copy.useItemInDefenseCopy(loc1.itemData.uid);
                }
                this.startPropCd();
            }
            return;
        }

        public startPropCd(): void
        {
            this._cd.totalTime = 2000;
            this._cd.reset();
            var loc1=0;
            while (loc1 < this._propVec.length) 
            {
                if (this._propVec[loc1].dragSource) 
                {
                    this._propVec[loc1].doCoolDown(this._cd, true);
                }
                ++loc1;
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.setPropListData([]);
            return;
        }

        protected removeFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._btnHide != null) 
            {
                ToolTipsManager.unregister(this._btnHide);
            }
            return;
        }

        public set hideTweeingTime(arg1: number)
        {
            this._hideTweeingTime = arg1;
            return;
        }

        protected /* var */_propVec: Vector.<ShortcutsItem>;

        protected /* var */_moveRec: Object /* flash.geom.Rectangle */;

        protected /* var */_moveBtn: GButton;

        protected /* var */_propList: Array<any>;

        protected /* var */_cd: CDItemData;

        protected /* var */_skillMaxNum: int;

        protected /* var */_skillBgNoSkillWidth: int=49;

        protected /* var */_skillSlotWidth: int=41;

        protected /* var */_skillDefaultNum: int=5;

        protected /* var */_container: Object /* flash.display.Sprite */;

        protected /* var */_btnHide: Object /* flash.display.DisplayObject */;

        protected /* var */_needHideBtn: Boolean;

        protected /* var */_showingTips: string;

        protected /* var */_hidingTips: string;

        protected /* var */_tweening: Boolean=false;

        protected /* var */_hideTweeingTime: number=0.25;

        protected /* var */_needShowNum: Boolean;
    }
